faApp.controller('SettingListCtrl',['$scope','settingService','$location','$controller','$route',
  function($scope,settingService,$location,$controller,$route) {   

    $controller('BaseCtrl', {$scope: $scope}); 

    $scope.settings = [];
    $scope.loading = true;

    $scope.$watch('config',function(){
      settingService.settingList($scope.config).then(function(json){
        $scope.settings = json.apiSettingList;
        $scope.pager = json.pager;
        $scope.loading = false;
      });
    },true);

    $scope.isEdit = {};
    $scope.settingsValue = {};

  // 显示编辑框
  $scope.toUpdate = function(id){
    $($scope.settings).each(function(i){
      $scope.isEdit[$scope.settings[i]['id']] = false;
    });

    $scope.isEdit[id] = true;
  };
  
  // 保存编辑内容
  $scope.updateValue = function(id){
    settingService.settingUpdate({id:id,settingValue:$scope.settingsValue[id]}).then(function(json){
      if(json.statusCode){
        alert("出错了:" + json.statusCode);
      }else{
        $scope.alertNextPage("修改成功！");
        $route.reload();
      }
    });
  }

}]);